<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<style>
.td_item {
    height:30px; 
    line-height: 30px; 
    width: 100%;   
    vertical-align: middle; 
    margin:0px; 
    padding:0px 0px 0px 0px; 
    overflow: hidden;
    border-top:solid 1px #b7d1e6;
}

.td_item2 {
	height: 30px;
	line-height: 30px;
	width: 100%;
	vertical-align: middle;
	margin: 0px;
	padding: 0px 0px 0px 0px;
	overflow: hidden;
	
}

.checkboxWidth {
	width: 200px;
}

.td_item_span {
	display: block;
	text-align: center;
	width: 71% !important;
}
</style>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<c:set var="grant_code">
	<x:out select="$xmlData/data/proposal/grant_code" />
</c:set>
<c:set var="sub_grant_code">
	<x:out select="$xmlData/data/proposal/sub_grant_code" />
</c:set>
<c:set var="nature_value">
	<x:out
		select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" />
</c:set>

<c:if test="${grant_code==635}">
	<!-- 635国家基础科学人才培养基金 -->
	<c:set var="Class">class="gray" </c:set>
</c:if>
<c:if test="${fn:substring(nature_value,0,1)=='A' }">
<div style="margin-bottom: 5px;">
    		<strong>温馨提示：</strong><br/>
    		<security:authorize ifNotGranted="A_DAILU_PROPOSAL">
    		单位财务信息从【单位维护表】中导入，由单位管理员填写，如有疑问请联系单位管理员进行修改。 
    		</security:authorize>
    		<security:authorize ifAnyGranted="A_DAILU_PROPOSAL">
    		单位财务信息从【单位维护表】中导入，如有数据需要调整，请您到【系统管理】->【单位信息维护】功能进行修改 。
    		</security:authorize>
</div>
</c:if>
<div class="t_bar">
	<c:if test="${fn:substring(nature_value,0,1)=='B' }">
		<span class="color_red">*</span>
	</c:if>
单位财务情况（单位：万元）</div>
<table width="100%" border="0" cellpadding="0" cellspacing="1"
	id="finances" class="t_css">
	<tr class="t_tr">
		<td align="center" width="40%" >指标
			<input type="hidden" name="organization/finance/nature_value" value="<x:out
		select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" />" />
		</td>
		<td align="center" width="60%">上年度（${year-1 }）年</td>
	</tr>
	
	<!-- 企业财务 -->
	<c:set var="finance_items"
		value="&nbsp;&nbsp;营业（销售）收入,
				 &nbsp;&nbsp;主营业务收入,
				 &nbsp;&nbsp;利润总额,
				 &nbsp;&nbsp;主营业务利润,
				 &nbsp;&nbsp;净利润,
				 &nbsp;&nbsp;纳税总额,
				 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中，增值税,
				 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中，营业税,
				 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中，企业所得税,
				 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中，个人所得税,
				 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中，其他税,
				 &nbsp;&nbsp;年末资产总额,
				 &nbsp;&nbsp;其中：年末固定资产净值,
				 &nbsp;&nbsp;年末负债总额,
				 &nbsp;&nbsp;年末资产负债率（%）,
				 &nbsp;&nbsp;总现金流量净额,
				 &nbsp;&nbsp;经营活动现金流量净额"
		scope="page"></c:set>
		<c:if test="${fn:substring(nature_value,0,1)=='A' }">
		<tr class="li_1" id="finance_enterprise">
			<td style="padding: 0px">
			    <c:forEach items="${fn:split(finance_items, ',') }" var="item" varStatus="sta">
						<div class="td_item" 
							<c:if test="${sta.index%2!=0 }">style="background:#f1f1f1;"</c:if>><span style="text-align:left">${item}</span>
						</div>
				</c:forEach>
		   </td>
			<c:set value="1" var="index" scope="page" />
			<x:forEach select="$xmlData/data/organization/finances/finance" var="finance" varStatus="finSta">
				<c:if test="${finSta.index>0 }">
					<c:set var="finance_type"><x:out select="$finance/@type" /></c:set>
					<c:if test='${finance_type=="企业财务" }'>
						<c:if test="${index==4 }">
							<td style="border-left: 1px solid #FFF;" id="td_item_${index}_0">
								 <input type="hidden" name="organization/finance@type" value="企业财务" />
								
								<div class="td_item" id="td_item_${index}_1">
									<span name="organization/finance/income">
										<x:out select="$finance/income" />
									</span>
								</div>
								
								<div class="td_item" id="td_item_${index}_2">
									<span name="organization/finance/income_main">
										<x:out select="$finance/income_main" />
									</span>
								</div>
								
								<div class="td_item" id="td_item_${index}_3">
									<span name="organization/finance/proft_total"><x:out
											select="$finance/proft_total" /></span>
								</div>
								
								<div class="td_item" id="td_item_${index}_4">
									<span 
										name="organization/finance/proft_main"><x:out
											select="$finance/proft_main" /></span>
								</div>
								
								<div class="td_item" id="td_item_${index}_5">
									<span 
										name="organization/finance/proft"><x:out
											select="$finance/proft" /></span>
								</div>
								
								<div class="td_item" id="td_item_${index}_6">
									<span	name="organization/finance/fax">
										<x:out select="$finance/fax" />
									</span>
								</div>
								
								<div class="td_item" id="td_item_${index}_7">
									<span name="organization/finance/fax_added"><x:out
											select="$finance/fax_added" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_8">
									<span i
										name="organization/finance/fax_bussiness"><x:out
											select="$finance/fax_bussiness" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_9">
									<span  
										name="organization/finance/fax_income"><x:out
											select="$finance/fax_income" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_10">
									<span 
										name="organization/finance/fax_personal"><x:out
											select="$finance/fax_personal" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_11">
									<span 
										name="organization/finance/fax_other"><x:out
											select="$finance/fax_other" /></span>
								</div>
								

								<div class="td_item" id="td_item_${index}_12">
									<span  id="finance_930_${index }" 
										name="organization/finance/assets"><x:out
											select="$finance/assets" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_13">
									<span 
										name="organization/finance/assets_fixed"><x:out
											select="$finance/assets_fixed" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_14">
									<span id="finance_932_${index }" 
										name="organization/finance/liabilities"><x:out
											select="$finance/liabilities" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_15">
									<span id="finance_935_${index }" 
										name="organization/finance/liabilities_pre"><x:out
											select="$finance/liabilities_pre" /></span>
								</div>
								
								
								<div class="td_item" id="td_item_${index}_16">
									<span 
										name="organization/finance/caseflow"><x:out
											select="$finance/caseflow" /></span>
								</div>
								<div class="td_item" id="td_item_${index}_17">
									<span 
										name="organization/finance/caseflow_active"><x:out
											select="$finance/caseflow_active" /></span>
								</div>
								</td>
						</c:if>
						<c:set value="${index+1 }" var="index" scope="page" />
					</c:if>
				</c:if>
			</x:forEach>
		</tr>
		</c:if>
		
		<!-- 事业财务 -->
		<c:set var="finance_items"
		value="&nbsp;&nbsp;年度总收入,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：事业收入,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：经营收入,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：其他收入,
		&nbsp;&nbsp;年度总收入增长率(%),
		&nbsp;&nbsp;年度总支出,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：事业支出,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：经营支出,
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其中：其他支出,
		&nbsp;&nbsp;年末资产总额,
		&nbsp;&nbsp;其中：年末固定资产原值,
		&nbsp;&nbsp;年末负债总额,
		&nbsp;&nbsp;年末资产负债率（%）,
		&nbsp;&nbsp;总现金流量净额,
		&nbsp;&nbsp;经营活动现金流量净额"
		scope="page"></c:set>

	<c:if test="${fn:substring(nature_value,0,1)=='B' }">
	<tr class="li_1" id="finance_career">
		<td style="padding: 0px">
			<c:forEach items="${fn:split(finance_items, ',') }" var="item" varStatus="sta">
				<div class="td_item"
					<c:if test="${sta.index%2!=0 }">style="background:#f1f1f1;"</c:if>>${item }
				</div>
			</c:forEach>
		</td>
		<c:set value="1" var="index" scope="page" />
		<x:forEach select="$xmlData/data/organization/finances/finance"
			var="finance">
			<c:set var="finance_type">
				<x:out select="$finance/@type" />
			</c:set>
			 <c:if test="${finance_type=='事业财务' }">
				<c:if test="${index==4 }">
					<td style="border-left: 1px solid #FFF;" <c:if test="${index!=4 }">style="display:none;"</c:if>>
						<input type="hidden" name="organization/finances@type" value="事业财务" />
						
						<div class="td_item" align="center" >
							<input  style="text-align: right;" id="a"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css gray required " disabled label="年度总收入"
							name="finances/income_total" 
							value="<x:out 
							select="$xmlData/data/finances/income_total" />" />
						</div>
						<div class="td_item" align="center" style="background:#f1f1f1;">
						   <input  style="text-align: right;" id="income_tech" onchange="sumIncome();"; 
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年度总收入-->事业收入"
							name="finances/income_tech" 
							value="<x:out 
							select="$xmlData/data/finances/income_tech" />" />
						</div>
						<div class="td_item" align="center" >
							<input  style="text-align: right;" id="income_product" onchange="sumIncome();"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年度总收入-->经营收入"
							name="finances/income_product" 
							value="<x:out 
							select="$xmlData/data/finances/income_product" />" />
						</div>
						<div class="td_item" align="center" style="background:#f1f1f1;" >
							<input  style="text-align: right;" id="income_other" onchange="sumIncome();"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年度总收入-->其他收入"
							name="finances/income_other" 
							value="<x:out 
							select="$xmlData/data/finances/income_other" />" />
						</div>
						<div class="td_item" align="center" >
							<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,2,2)" 
							class="input_css required " label="年度总收入增长率"
							name="finances/income_rate" 
							value="<x:out 
							select="$xmlData/data/finances/income_rate" />" />
						</div>
						<div class="td_item" align="center" style="background:#f1f1f1;" >
							<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,4,2)" id="b"
							class="input_css required gray" disabled label="年度总支出"
							name="finances/outcome" 
							value="<x:out 
							select="$xmlData/data/finances/outcome" />" />
						</div>
						<div class="td_item" align="center" >
							<input  style="text-align: right;" id="outcome_tech"
							onfocus="InitInput.setNumber(this,9,4,2)" onchange="sumOutcome();"
							class="input_css required " label="年度总支出-->事业支出"
							name="finances/outcome_tech" 
							value="<x:out 
							select="$xmlData/data/finances/outcome_tech" />" />
						</div>
						<div class="td_item" align="center" style="background:#f1f1f1;" >
							<input  style="text-align: right;" id="outcome_product"
							onfocus="InitInput.setNumber(this,9,4,2)" onchange="sumOutcome();"
							class="input_css required " label="年度总支出-->经营支出"
							name="finances/outcome_product" 
							value="<x:out 
							select="$xmlData/data/finances/outcome_product" />" />	
						</div>
						<div class="td_item" align="center" >
							<input  style="text-align: right;" id="outcome_other"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年度总支出-->其他支出" onchange="sumOutcome();"
							name="finances/outcome_other" 
							value="<x:out 
							select="$xmlData/data/finances/outcome_other" />" />
						</div>
							<div class="td_item" align="center" style="background:#f1f1f1;">
							<input  style="text-align: right;"  id="assets"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年末资产总额"
							name="finances/assets" 
							value="<x:out 
							select="$xmlData/data/finances/assets" />" />
						</div>
					<div class="td_item"  align="center">
						<input  style="text-align: right;" id="assets_fixed"
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required valueCompare:assets_fixed:assets" label="年末固定资产原值"
							name="finances/assets_fixed" 
							value="<x:out 
							select="$xmlData/data/finances/assets_fixed" />" />
					</div>
								<div class="td_item" id="td_item_${index}_14" align="center" style="background:#f1f1f1;">
								<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="年末负债总额"
							name="finances/liabilities" 
							value="<x:out 
							select="$xmlData/data/finances/liabilities" />" />
								</div>
								<div class="td_item" id="td_item_${index}_15" align="center">
									<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,2,2)" 
							class="input_css required " label="年末资产负债率"
							name="finances/liabilities_pre" 
							value="<x:out 
							select="$xmlData/data/finances/liabilities_pre" />" />
								</div>
								<div class="td_item" id="td_item_${index}_16" align="center" style="background:#f1f1f1;">
									<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="总现金流量净额"
							name="finances/caseflow" 
							value="<x:out 
							select="$xmlData/data/finances/caseflow" />" />
								</div>
								<div class="td_item" id="td_item_${index}_17" align="center">
								<input  style="text-align: right;" 
							onfocus="InitInput.setNumber(this,9,4,2)" 
							class="input_css required " label="经营活动现金流量净额"
							name="finances/caseflow_active" 
							value="<x:out 
							select="$xmlData/data/finances/caseflow_active" />" />
								</div>
					</td>
				</c:if>
				<c:set value="${index+1 }" var="index" scope="page" />
			</c:if>
		</x:forEach>
	</tr>
	</c:if>
</table>
	
	
<script type="text/javascript">
	$(function() {
		$("#finance_935_4").text(thousandsNumber(formatVal($("#finance_932_4").text().replace(/,/g,'')*100/$("#finance_930_4").text().replace(/,/g,''))));
		

		$("#finance_enterprise").children("td:not(:first)").each(function(){
			setFinanceStyle($(this));
		});
		
		$("div[id^='td_item_1_']").hide();
		$("div[id^='td_item_2_']").hide();
		$("td[id^='td_item_1_']").hide();
		$("td[id^='td_item_2_']").hide();
		//$("div[id$=td_item_1_]").hide();
		
		$("#income_main_zc_4").addClass("required");
		
		
	});
	
	
	
	/*
	 * 设置财务样式
	 */
	 function setFinanceStyle(obj) {
		obj.css("padding", "0").children("div:odd").css("background", "#f1f1f1");
		obj.find("input").css("width", 120).css("margin-top", "3px").css("height", "18px");
		obj.find("span").attr("style", "width: 95%; text-align: center; display: block;");
	 }
	 /**
	  * 将值以千分位显示
	  * @param value 数值
	  */
	 function thousandsNumber(value) {
	 	if (value == null || value == undefined || value == "") {
	 		return "";
	 	}
	 	var negative = '';
	 	var intVal = value.split(".")[0];
	 	var j = intVal.length;
	 	if(intVal.charAt(0) == '-'){
	 		negative = '-';
	 		intVal = intVal.substr(1, j);
	 	}
	 	j = intVal.length;
	 	for(var i=j-3; i>0; i=i-3){
	 		intVal = intVal.substr(0, i) + "," + intVal.substr(i, j);
	 	}
	 	if(value.split(".")[1] != null){
	 		return (negative + intVal + '.' + value.split(".")[1]);
	 	} else{
	 		return (negative + intVal);
	 	}
	 }
	 
	 
	 function sumIncome(){
		 var total=parseFloat($('#income_product').val())+parseFloat($('#income_tech').val())+parseFloat($('#income_other').val());
		 total=formatVal2(total);	
		 $('#a').val(total);
	 }
	 
	 function sumOutcome(){
		 var total=parseFloat($('#outcome_product').val())+parseFloat($('#outcome_tech').val())+parseFloat($('#outcome_other').val());
		 total=formatVal2(total);	
		 $('#b').val(total);
		 
	 }
</script>

